package com.cxl.demo.controller;

import com.cxl.demo.mapper.RecordGradeMapper;
import com.cxl.demo.service.GradeAndConditionService;
import com.cxl.demo.vo.RecordGrade;
import com.cxl.demo.vo.ReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/gradeAndCondition")
@CrossOrigin
public class GradeAndConditionController {


    @Autowired
    GradeAndConditionService gradeAndConditionService;
    @Autowired
    RecordGradeMapper recordGradeMapper;
    @Autowired
    ReturnData returnData;

    @PostMapping("GetGradeList")
    public ReturnData GetGradeList(@RequestBody Map<String, Object> map) {
        returnData.setData(null);

        returnData.setMsg("查询完毕");
        returnData.setStatus(true);

        returnData.setData(gradeAndConditionService.getRecordGradeList());

        return returnData;
    }

    @PostMapping("GetConditionList")
    public ReturnData GetConditionList(@RequestBody Map<String, Object> map) {
        returnData.setData(null);

        returnData.setMsg("查询完毕");
        returnData.setStatus(true);
        returnData.setData(gradeAndConditionService.getRecordConditionList());


        return returnData;
    }


    @PostMapping("Update")
    public ReturnData Update(@RequestBody Map<String, Object> map) {
        returnData.setData(null);

        returnData.setMsg("修改完毕");
        returnData.setStatus(true);

        RecordGrade recordGrade = new RecordGrade();
        recordGrade.setRecordGradeId((Integer) map.get("recordGradeId"));
        recordGrade.setRecordGradeDescribe((String) map.get("recordGradeDescribe"));
        recordGrade.setRecordGradeDivide(Double.parseDouble((String) map.get("recordGradeDivide")));
        recordGradeMapper.UpGrade(recordGrade);


        return returnData;
    }
}
